<script>
	function perbuatan_dokumen(deperbNO){
		FBModal_show2(APP.action, 'post', 'proc=dokumen-modal&deperb_no='+deperbNO, true, true, null,
			{onSuccess: function(res){ perbuatan_dokument_image(deperbNO) }});
	}
	
	function perbuatan_dokument_image(deperbNO){
		var newimg = new Element('img', {
					src:APP.action+'?proc=img-file&deperb_no='+deperbNO+'&file='+(APP.imgFileNumber), 
					id:'perbuatan-img-view',
					style:'max-width:100%; max-height:400px',
					title:'Click to enlarge'});
				newimg.addEvent('load',function(){
					newimg.replaces($('perbuatan-img-view'));
					$('perbuatan-img-view').getParent('a').href=APP.action+'?proc=img-file&deperb_no='+deperbNO+'&file='+(APP.imgFileNumber);	
				});
	}
	
	//add ke golongan table
	function doAdd(){
		location.replace('dashboard.php?p=perbuatan&sub=perbuatan_add');
	}

	//edit golongan table
	//@param id (string) kode/id golongan 
	function perbuatan_edit(id){
		location.replace('dashboard.php?p=perbuatan&sub=perbuatan_edit');
	}
	
	//delete golongan
	//@param id (string) kode/id golongan 
	function perbuatan_delete(id){
		FBModal_loading("Delete", "Please wait...", false, false);
		doRequest(APP.action, 'post', 'proc=perbuatan-delete&perb_no='+id, 
			null,
			function(res){
				//update tablenya
				perbuatan_updateList();
				//alert(res);
				var js = JSON.decode(res);
				var msg = js.error? js.msg : "Process penghapusan selesai !!!";
				var title = js.error? 'Error' : 'Delete';
				
				FBModal_show(
					"<h2 class=\"dialog_title\"><span>"+title+"</span></h2>" + 
					"<div class=\"dialog_content\" style=\"padding: 10px 20px\">"+msg+"</div>",
					true, true);
			});
	}

	//update table
	function perbuatan_updateList(){
		key = $('key_key').value;
		status = $('key_status').value;
		doRequest(APP.action, 'post', 'proc=perbuatan-table&key='+key+'&status='+status+'&username=<?php echo $_COOKIE_DATA->username?>', 
			function (res){ 
				$('perbuatan-table').innerHTML = res;
		});
	}

	//save golongan
	function perbuatan_save(form, type){
		FBModal_loading("Save", "Please wait...", true, false);
		$(form).set('send', {
			onSuccess: function(response) { 
//				alert(response);
				var js = JSON.decode(response);
				var msg = js.error? js.msg : "Process simpan selesai !!!";
				var title = js.error? 'Error' : 'Saving';
				FBModal_show(
					"<h2 class=\"dialog_title\"><span>"+title+"</span></h2>" + 
					"<div class=\"dialog_content\" style=\"padding: 10px 20px\">"+msg+"</div>",
					true, true);

				perbuatan_updateList();
			}
		}).send();
	}

	window.addEvent('domready', function(){
		perbuatan_updateList();
	});
	
	function perbuatan_updateStatus(el, deperbNO, status){
		doRequest(APP.action, 'post', 'proc=perbuatan-activate&deperbNO='+deperbNO+'&status='+status, 
			function(){
				var x = el.getParent('tr');
				x.get('tween').chain(function(){
					x.destroy();
				}).start('opacity',[1,0]);
			});
	}
	
	function perbuatan_dokumen(deperbNO){
		FBModal_show2(APP.action, 'post', 'proc=dokumen-modal&deperb_no='+deperbNO, true, true, null,
			{onSuccess: function(res){ perbuatan_dokument_image(deperbNO) }});
	}
	
	function perbuatan_dokument_image(deperbNO){
		var newimg = new Element('img', {
					src:APP.action+'?proc=img-file&deperb_no='+deperbNO+'&file='+(APP.imgFileNumber), 
					id:'perbuatan-img-view',
					style:'max-width:100%; max-height:400px',
					title:'Click to enlarge'});
				newimg.addEvent('load',function(){
					newimg.replaces($('perbuatan-img-view'));
					$('perbuatan-img-view').getParent('a').href=APP.action+'?proc=img-file&deperb_no='+deperbNO+'&file='+(APP.imgFileNumber);	
				});
	}
	
	APP= {
		action: 'proc/client/perbuatan.php',
		imgFileNumber: 0
	}
</script>

<div>
<form>
Search : <input id="key_key" name="key_key" type="text" class="marginL5" onkeyup="perbuatan_updateList()" style="width:200px; margin-right:20px" />
Status : 
<select id="key_status" name="key_status" type="text" style="margin-right:20px" onchange="perbuatan_updateList()">
    <option value="0">Pending</option>
    <option value="1">Denied</option>
    <option value="2">Approve</option>
</select>
</form>
</div>
<table class="marginT5 list" width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr class="header">
    <th><a>Tgl Lapor</a></th>
    <th><a>Tgl Kejadian</a></th>
    <th><a>Pelaku</a></th>
    <th><a>Bidang</a></th>
    <th><a>Tingkat</a></th>
    <th><a>Kategori</a></th>
    <th><a>Status</a></th>
    <th>&nbsp;</th>
  </tr>
  <tbody id="perbuatan-table"></tbody>
</table>
<div style="width:100%" align="right"><a class="fake" onclick="doAdd()">Add</a></div>